package projectEuler.net;
/**
 * Find the largest palindrome made from the product of two 3-digit numbers.
 * @author xrose
 *
 */
public class Problem_004 {
	private static int largestPalindrome;
	private static void init(){
		largestPalindrome = 0;
	}
	private static boolean isPalindrome(int abba){
		int abab = abba;
		int temp = 0;
		int nodigit = 0;
		while(abab>0){
			nodigit++;
			abab/=10;
		}
		abab = abba;
		for(int i=nodigit-1; i>=0; i--){
			temp+=(Math.pow(10, i)*(abab%10));
			abab/=10;
		}
		return (temp==abba);
	}
	public static void setLargestPalindrome(int largestPalindrome) {
		if(isPalindrome(largestPalindrome)){
			if(largestPalindrome>Problem_004.largestPalindrome)
				Problem_004.largestPalindrome = largestPalindrome;
		}
	}
	public static int getLargestPalindrome() {
		return largestPalindrome;
	}
	public static int maxPalindrome(){
		init();
		for(int i=100; i<1000; i++)
			for(int j=100; j<1000; j++){
				setLargestPalindrome(i*j);
			}
		return largestPalindrome;
	}
}
